package com.hyfrogx.modules.information.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.modules.information.entity.HyInformationVerifyEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author liubin
 * @date 2019/10/21 10:53
 */
@Mapper
public interface HyInformationVerifyDao extends BaseMapper<HyInformationVerifyEntity> {

  /**
   * 查询用户信息，审核信息
   * @param uid
   * @return
   */
  @Select("SELECT\n" +
    "\tu.head,u.signature,v.* \n" +
    "FROM\n" +
    "\thy_information_verify v\n" +
    "\tLEFT JOIN hy_user u ON u.uid = v.uid \n" +
    "WHERE\n" +
    "\tv.uid = #{uid}\n")
  HyInformationVerifyEntity getVerifyRecordByUid(@Param("uid") Integer uid);

  /**
   * 查询审核记录
   * @param query
   * @param map
   * @return
   */
  List<HyInformationVerifyEntity> getAllVerifyRecord(QueryExt query,  @Param("map") Map map);

  /**
   * 查询所有未关注的资讯号
   * @param query
   * @param map
   * @return
   */
  List<HyInformationVerifyEntity> getAllNotFollowClient(QueryExt query,  @Param("map") Map map);

  @Select("SELECT\n" +
    "\tv.user_name,u.head,v.uid\n" +
    "FROM\n" +
    "\thy_information_verify v\n" +
    "\tLEFT JOIN hy_user u ON u.uid = v.uid \n" +
    "WHERE\n" +
    "\tv.enable_state = 1 AND v.verify_status = 1\n" +
    "AND v.is_recommend =1\n")
  List<HyInformationVerifyEntity> getAllRecommendReordClient();

  /**
   * 查询所有关注的资讯号的头像名字，按资讯更新时间倒序，关注事件倒序
   * @return
   */
  @Select("SELECT\n" +
    "\tv.user_name,\n" +
    "\t\tu.head,\n" +
    "\t\tv.uid\n" +
    "FROM\n" +
    "\thy_information_verify v\n" +
    "\tJOIN hy_user u ON v.uid = u.uid"+
    "\tLEFT JOIN hy_user_attention a ON a.sid\n" +
    "\t\t= v.uid\n" +
    "\t\tLEFT JOIN hy_information m ON v.phone = m.publisher\n" +
    "WHERE\n" +
    "\ta.fid =#{fid,jdbcType=INTEGER}\n" +
    "\t\tand v.enable_state=1\n" +
    "\t\tand v.verify_status=1\n" +
    "\t\tGROUP BY v.uid\n" +
    "\t\tORDER BY\n" +
    "\t\tm.publish_time DESC,\n" +
    "\t\ta.created LIMIT 0,20\n" )
  List<HyInformationVerifyEntity> getAllFollowRecordClient1(@Param("fid") Integer fid);

  /**
   * 查询所有关注的资讯号的头像名字，按资讯更新时间倒序，关注事件倒序
   * @param verify
   * @return
   */
  @Select("SELECT\n" +
    "v.uid,\n" +
    "v.user_name,\n" +
    "v.authentication_information,\n" +
    "v.company_name,\n" +
    "u.head,\n" +
    "u.signature,\n" +
    "m.id as mid,\n" +
    "m.publish_time as publishTime,\n" +
    "m.title as title,\n" +
    "(m.attention + m.wx_click + m.qq_click) AS attentions,\n" +
    "m.share_img as shareImg,\n" +
    "m.is_advertising as isAdvertising,\n" +
    "m.tj_top as tjTop,\n" +
    "m.share_depict as shareDepict,\n" +
    "m.advertising_url as advertisingUrl,\n" +
    "m.video_url as videoUrl,\n" +
    "m.is_atlas as isAtlas,\n" +
    "m.template_type as templateType,\n" +
    "m.publisher as publisher\n" +
    "FROM\n" +
    "hy_information m\n" +
    "LEFT JOIN hy_information_verify v ON v.operator_phone = m.publisher\n" +
    "LEFT JOIN hy_user_attention b ON v.uid = b.sid\n" +
    "LEFT JOIN hy_user u ON\n" +
    "v.uid = u.uid\n" +
    "WHERE\n" +
    " v.verify_status = 1\n" +
    "AND b.fid = #{verify.fid,jdbcType=INTEGER}\n" +
    "AND m.state=1\n" +
    "AND v.enable_state=1\n" +
    "GROUP BY\n" +
    "m.id\n" +
    "ORDER BY\n" +
    "m.update_time DESC,\n" +
    "v.create_time DESC\n" )
  List<HyInformationVerifyEntity> getAllFollowRecordClient(QueryExt query, @Param("verify") Map<String, Object> verify);

  /**
   * 查询资讯号账户信息
   * @param userId
   * @return`
   */
  @Select("SELECT\n" +
    "\t\tu.head as head,\n" +
    "\t\tv.authenticationInformation,\n" +
    "\t\tu.signature as\n" +
    "\t\tsignature,\n" +
    "\t\tv.phone,\n" +
    "\t\tv.user_name,\n" +
    "\t\tv.company_name,\n" +
    "\t\tv.tel,\n" +
    "\t\tv.address,\n" +
    "\t\tv.company_profile,\n" +
    "\t\tv.video,\n" +
    "\t\tv.enable_state,v.verify_status\n" +
    "\t\tFROM\n" +
    "\t\thy_information_verify v\n" +
    "\t\tLEFT JOIN\n" +
    "\t\thy_user u ON u.uid = v.uid"+
    "\t\twhere\n"+
    "\t\tv.uid =#{userId}\n")
  HyInformationVerifyEntity getAccountByUid(@Param("userId") long userId);

  List<HyInformationVerifyEntity> getAllOperationCenter(QueryExt query, @Param("map") Map map);
}
